package com.example.demo.controller;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.domain.UserEntity;
import com.example.demo.util.RedisUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@Api(description = "用户操作接口")
public class RedisController {

    private static int ExpireTime = 60; // redis中存储的过期时间60s

    @Resource
    private RedisUtil redisUtil;

    @PutMapping("set")
    @ApiOperation(value = "添加一个用户", notes = "用户信息")
    public boolean redisset(@RequestParam String key, @RequestParam String value) {
        return redisUtil.set(key, value);
    }

    @GetMapping("get/")
    public Object redisget(String key) {
        return redisUtil.get(key);
    }

    @PutMapping("expire")
    public boolean expire(String key) {
        return redisUtil.expire(key, ExpireTime);
    }
}
